import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hansheng.dao.MaterialDao;
import com.hansheng.entity.MaterialEntity;

import java.util.List;

/**
 * Created by GoldenMan on 2017/5/29.
 */
public class testMaterialDao extends SpringTestCase {
    private MaterialDao materialDao;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        materialDao = (MaterialDao) getFactory().getBean("materialDao");
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testMaterialDao(){
        String whereHql = "where o.fatherMid is null";
        Object[] params = {};
        List<MaterialEntity> list = materialDao.getFatherMaterialList(whereHql, params);
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < list.size(); i++) {
            JSONObject tempJson = new JSONObject();
            tempJson.put("mid", list.get(i).getMid());
            tempJson.put("material", list.get(i).getMaterial());
            tempJson.put("depository", list.get(i).getDepository());
            tempJson.put("fatherMid", list.get(i).getFatherMid());
            jsonArray.add(tempJson);
        }
        System.out.println(jsonArray.toString());
    }
}